<template>
  <div class="profile-container">
    <div class="profile-header">
      <h1>个人资料</h1>
    </div>

    <div class="profile-content">
      <div class="profile-section">
        <h2>基本信息</h2>
        <div class="profile-form">
          <div class="form-group">
            <label>用户名</label>
            <input type="text" v-model="profile.username" disabled />
          </div>
          
          <div class="form-group">
            <label>邮箱</label>
            <input type="email" v-model="profile.email" />
          </div>

          <div class="form-group">
            <label>昵称</label>
            <input type="text" v-model="profile.nickname" />
          </div>

          <div class="form-actions">
            <button class="btn-save" @click="saveProfile">保存修改</button>
          </div>
        </div>
      </div>

      <div class="profile-section">
        <h2>修改密码</h2>
        <div class="profile-form">
          <div class="form-group">
            <label>当前密码</label>
            <input type="password" v-model="passwordForm.currentPassword" />
          </div>

          <div class="form-group">
            <label>新密码</label>
            <input type="password" v-model="passwordForm.newPassword" />
          </div>

          <div class="form-group">
            <label>确认新密码</label>
            <input type="password" v-model="passwordForm.confirmPassword" />
          </div>

          <div class="form-actions">
            <button class="btn-save" @click="changePassword">更改密码</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'UserProfile',
  data() {
    return {
      profile: {
        username: 'user123',
        email: '',
        nickname: ''
      },
      passwordForm: {
        currentPassword: '',
        newPassword: '',
        confirmPassword: ''
      }
    }
  },
  methods: {
    async saveProfile() {
      try {
        // TODO: 实现保存个人资料的逻辑
        console.log('保存个人资料', this.profile)
      } catch (error) {
        console.error('保存失败:', error)
      }
    },
    async changePassword() {
      try {
        if (this.passwordForm.newPassword !== this.passwordForm.confirmPassword) {
          alert('两次输入的密码不一致')
          return
        }
        // TODO: 实现修改密码的逻辑
        console.log('修改密码', this.passwordForm)
      } catch (error) {
        console.error('修改密码失败:', error)
      }
    }
  }
}
</script>

<style scoped>
.profile-container {
  max-width: 800px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.profile-header {
  margin-bottom: 2rem;
}

.profile-header h1 {
  font-size: 2rem;
  color: #333;
}

.profile-section {
  background: white;
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.profile-section h2 {
  margin-bottom: 1.5rem;
  color: #333;
  font-size: 1.5rem;
}

.profile-form {
  max-width: 500px;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.form-group input:disabled {
  background-color: #f5f5f5;
  cursor: not-allowed;
}

.form-actions {
  margin-top: 2rem;
}

.btn-save {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s;
}

.btn-save:hover {
  background-color: #0056b3;
}
</style> 